package com.zzyl.controller;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: NursingProjectController
 * @description:
 * @author: InnovatorX
 * @date: 2024/5/26 14:31
 * @Version: 1.0
 */
@RestController
@RequestMapping("/nursing_project")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页条件查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> findByPage(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) Integer status,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.findByPage(name, status, pageNum, pageSize);
        return success(pageResponse);
    }

    /**
     * 新增服务项目
     *
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    public ResponseResult save(@RequestBody NursingProjectDto nursingProjectDto) {
        NursingProjectVo bean = BeanUtil.toBean(nursingProjectDto, NursingProjectVo.class);
        nursingProjectService.save(bean);
        return success();
    }

    /**
     * 根据id查询护理
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult<NursingProjectVo> findById(@PathVariable("id") Long id) {
        NursingProjectVo nursingProject = nursingProjectService.findById(id);
        NursingProjectVo bean = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return success(bean);
    }

    /**
     * 修改大保健
     *
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        NursingProjectVo bean = BeanUtil.toBean(nursingProjectDto, NursingProjectVo.class);
        nursingProjectService.update(bean);
        return success();
    }

    /**
     * 当前状态
     *
     * @param id
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable(name = "id") Long id,
                                 @PathVariable(name = "status") Integer status) {
        nursingProjectService.updateBySta(id, status);
        return success();
    }

    /**
     * 删除护理项目
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        nursingProjectService.deleteById(id);
        return success();
    }

    /**
     * 查询所有护理项目
     *
     * @return
     */
    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVo>> findAll() {
        List<NursingProjectVo> voList = nursingProjectService.findAll();
        return success(voList);
    }
}
